﻿using ETS.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETS.Interface
{
    /// <summary>
    /// 抽象的评分器类
    /// (注-组合模式：安全模式，没有在此抽象类里加Add和Remove)
    /// </summary>
    public abstract class AbstractEvaluator
    {
        public Dictionary<string, AbstractEvaluator> FeatureDictionary = new Dictionary<string, AbstractEvaluator>();

        /// <summary>
        /// 名称
        /// </summary>
        protected string _name;

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="name"></param>
        public AbstractEvaluator(string name)
        {
            _name = name;
        }

        /// <summary>
        /// 评分
        /// (注-模板方法模式：去评分是可变的，做分数持久化固定的)
        /// </summary>
        /// <returns></returns>
        public Score Evaluate()
        {
            Score score = DoEvaluate();//去评分是可变的
            //做分数持久化固定的，把成绩记录到输出设备中
            string filePath = @"C:\WorkSpace\score.txt";
            if (!File.Exists(filePath))
            {
                File.Create(filePath);
            }
            using (StreamWriter sw = new StreamWriter(filePath, true))
            {
                sw.WriteLine(score);
                sw.Flush();
                sw.Close();
            }

            return score;
        }

        /// <summary>
        /// 去做评分
        /// </summary>
        /// <returns></returns>
        public virtual Score DoEvaluate() =>  0 ;

        /// <summary>
        /// 显示部分与整体的层次结构
        /// </summary>
        /// <param name="depth"></param>
        public abstract void Display(int depth);
    }
}
